// Stand-up targets for a pinball machine
//
// (c)2012 Felipe Sanches <fsanches@metamaquina.com.br>
// licensed under GPLv3 or later

inch = 25.4;//mm

module wide_standup_target(target_color="red"){
  width = (1+11/32)*inch;
  height = 1*inch;
  thickness = 3/8*inch;
  standup_target(width, height, thickness, target_color);
}

module narrow_standup_target(target_color="red"){
//TODO: check dimensions
  width = (3/4)*inch;
  height = 1*inch;
  thickness = 3/8*inch;
  standup_target(width, height, thickness, target_color);
}

module square_standup_target(target_color="red"){
//TODO: check dimensions
  width = 1*inch;
  height = 1*inch;
  thickness = 3/8*inch;
  standup_target(width, height, thickness, target_color);
}

module standup_target(width, height, thickness, target_color){

  color(target_color)
  difference(){
    cube([width, thickness, height], center=true);

    rotate([90,0,0])
    cylinder(r=(1/8)*inch, h=2*thickness, $fn=20, center=true);
  }

  color("silver")
  translate([0,-thickness/2])
  scale([1,0.3,1])
  sphere(r=(1/8*4/5)*inch, $fn=20);
}

module switch_body(){
  thickness=1.5;
  support_width=10;
  support_length=67;
  support_playfield_depth=32;

  //back of the switch: 
  translate([-support_width/2, 4.3, -support_playfield_depth])
  cube([support_width, thickness, support_length]);

  //metalic contact of the switch: 
  translate([-support_width/2, 4.3 - 6, -support_playfield_depth])
  cube([support_width, thickness/4, support_length]);

  //cork sandwich: 
  color("tan"){
    translate([-support_width/2, 4.3 - 5.4, -support_playfield_depth])
    cube([support_width, 5.2, (3/5)*support_playfield_depth]);

    translate([-support_width/2, 4.3 - 5.4 - 4, -support_playfield_depth])
    cube([support_width, 3, (3/5)*support_playfield_depth]);
  }

  //screws:
  for (i=[1,-1]){
    translate([0,0,-support_playfield_depth*(1-3/10 + i/7)])
    rotate([90,0,0])
    cylinder(r=3,h=6, $fn=30);
  }
}

module single_target_support(){
  thickness=1.5;
  support_width=10;
  support_length=67;
  support_playfield_depth=32;
  screws_support_width=19;
  screws_support_height=9.5;

  //'L'-shaped metal
  union(){
    translate([-support_width/2, thickness+4.3, -support_playfield_depth])
    cube([support_width, thickness, support_playfield_depth]);

    translate([-support_width/2, 2*thickness+4.3,-thickness])
    cube([support_width, 2*thickness, thickness]);
  }

  translate([0,9 + screws_support_height/2, -thickness])
  linear_extrude(height=thickness)
  difference(){
    square([screws_support_width, screws_support_height], center=true);

    //screw holes
    for (i=[-1,1]){
      translate([i*4.5,0])
      circle(r=2.5, $fn=30);
    }
  }
}

module bank_target_support(){
  support_width=10;
  support_length=67;
  support_playfield_depth=32;
  screws_support_width=19;
  screws_support_height=9.5;

  //TODO: implement-me!
}

module standup(target_color="red", playfield_thickness=15){
  //part number 
  //WMS #A-20499-9

//TODO: hows that different from #A-20846-4 ?

  translate([0,0, -playfield_thickness]){
    translate([0,0,(1 + 1/16)*inch])
    wide_standup_target(target_color);

    switch_body();
    single_target_support();
  }
}

module standup_footprint(){
  //2D footprint of the part
  projection(cut = false){
    wide_standup_target();
    switch_body();
    single_target_support();
  }
}

module standup_bank3_mount_holes(playfield_thickness){
//3D description of the cut to be made in the playfield wood
//TODO: verify-me for correctness...
  inch=25.4;
  translate([0,0,-playfield_thickness-1])
  linear_extrude(height=playfield_thickness+2)
  minkowski(){
    projection(cut = true){
      translate([0,0,-1/2*inch]){
        for (i=[-1,0,1]){
          translate([i*33, 0]){
            wide_standup_target();
            switch_body();
          }
        }
      }
    }
    circle(r=4);
  }
}


module standup_mount_holes(playfield_thickness=15){
//3D description of the cut to be made in the playfield wood
  inch=25.4;
  translate([0,0,-playfield_thickness-1])
  linear_extrude(height=playfield_thickness+2)
  minkowski(){
    projection(cut = true){
      translate([0,0,-1/2*inch]){
        wide_standup_target();
        switch_body();
      }
    }
    circle(r=4);
  }
}

module standup_bank3(target_color="orangered", playfield_thickness=15){
  //http://www.marcospecialties.com/pinball-parts/A-19294
  //Part#: A-19294 

  translate([0,0, -playfield_thickness]){
    for (i=[-1,0,1]){
      translate([i*33, 0]){
        translate([0, 0, (1 + 1/16)*inch])
        square_standup_target(target_color);

        switch_body();
      }
    }

    bank_target_support();
  }
}

translate([0,-50]) standup();
standup_bank3();
